﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using control.Dal;

namespace control.Biz
{
    public class BizSach
    {
        private int idSach;

        public int IdSach
        {
            get { return idSach; }
            set { idSach = value; }
        }
        private string maSach;

        public string MaSach
        {
            get { return maSach; }
            set { maSach = value; }
        }
        private string tenSach;

        public string TenSach
        {
            get { return tenSach; }
            set { tenSach = value; }
        }
        private BizChuDe chuDe;

        public BizChuDe ChuDe
        {
            get { return chuDe; }
            set { chuDe = value; }
        }
        private string tacGia;

        public string TacGia
        {
            get { return tacGia; }
            set { tacGia = value; }
        }
        private int namXB;

        public int NamXB
        {
            get { return namXB; }
            set { namXB = value; }
        }
        private float giaSach;

        public float GiaSach
        {
            get { return giaSach; }
            set { giaSach = value; }
        }
        private DateTime ngayCapNhat;

        public DateTime NgayCapNhat
        {
            get 
            {
                if (DateTime.Compare(ngayCapNhat,DateTime.MinValue)<=0)
                {
                    ngayCapNhat = DateTime.Now;
                }
                return ngayCapNhat; 
            
            }
            set { ngayCapNhat = value; }
        }
        private string hinh;
        public string Hinh 
        {
            get
            {
                if (hinh == null)
                    hinh = "";
                return hinh;
            }
            set { hinh = value; } 
        }
        public bool IsEnable { get; set; }
        public string TenChuDe
        {
            get 
            {
                if (chuDe==null)
                {
                    chuDe = new BizChuDe();
                }
                return chuDe.TenChuDe; 
            }
        }
        #region newver
        public string MoTa { get; set; }
        public string IconNew
        {
            get 
            { 
                if(DateTime.Compare(NgayCapNhat,DateTime.Today.AddMonths(-1)) >= 0)
                    return "<img src='images/new_icon.gif' alt='' title='' />";
                else
                    return null;
            }
        }
        #endregion
        public BizSach(int _idSach,string _maSach,string _tenSach,string _tacGia,int _namXB,float _giaBan,DateTime _ngayCapNhat,BizChuDe _chuDe,string _Hinh,string _MoTa,bool _IsEnable)
        {
            idSach = _idSach;
            maSach = _maSach;
            tenSach = _tenSach;
            tacGia = _tacGia;
            namXB = _namXB;
            giaSach = _giaBan;
            ngayCapNhat = _ngayCapNhat;
            chuDe = _chuDe;
            Hinh = _Hinh;
            MoTa = _MoTa;
            IsEnable = _IsEnable;
            
        }
        public BizSach()
        {

        }
        public static List<BizSach> GetAll()
        {
            
            return DalSach.GetAll();
        }

        public void Insert()
        {
            idSach = DalSach.Insert(this);
        }

        public void Update()
        {
            DalSach.Update(this);
        }

        public void Delete()
        {
            DalSach.Delete(this);
        }



        public static BizSach GetSachByID(int _ID)
        {
            return DalSach.GetSachByID(_ID);
        }

        public static List<BizSach> GetNewSach()
        {
            return DalSach.GetNewSach();
        }

        public static List<BizSach> GetRandom()
        {
            return DalSach.GetRandom();
        }

        public static List<BizSach> GetSachByIDLoai(int _MaCD)
        {
            return DalSach.GetSachByIDLoai(_MaCD);
        }

        public static List<BizSach> Find(string _TenSach, int _IDChuDe)
        {
            return DalSach.Find(_TenSach,_IDChuDe);
        }

        public static List<BizSach> GetTopSeller()
        {
            return DalSach.GetTopSeller();
        }

        public static List<BizSach> Find(string sach, int IDchude, int giatu, int giaden, bool dangban)
        {
            return DalSach.Find(sach,IDchude,giatu,giaden,dangban);
        }
        //thong ke 
        private int soLuong;

        public int SoLuong
        {
            get { return soLuong; }
        }
        public BizSach(int _idSach, string _maSach, string _tenSach, string _tacGia, int _namXB, float _giaBan, DateTime _ngayCapNhat, string _hinh, bool _isEnable, string _mota, BizChuDe _chuDe, int _soLuong)
        {
            idSach = _idSach;
            maSach = _maSach;
            tenSach = _tenSach;
            tacGia = _tacGia;
            namXB = _namXB;
            giaSach = _giaBan;
            ngayCapNhat = _ngayCapNhat;
            hinh = _hinh;
            IsEnable = _isEnable;
            chuDe = _chuDe;
            soLuong = _soLuong;
            MoTa = _mota;
        }

        public static List<BizSach> XemTKTheoChuDe(int idChuDe,DateTime datetp_Batdau,DateTime dateTP_ngayKT)
        {
            return DalSach.XemTKTheoChuDe(idChuDe, datetp_Batdau, dateTP_ngayKT);
        }
        public static List<BizSach> XemTKTatCaChuDe(DateTime datetp_Batdau,DateTime dateTP_ngayKT)
        {
            return DalSach.XemTKTatCaChuDe(datetp_Batdau, dateTP_ngayKT);
        }


        public static List<BizSach> XemThongKe(int soLuongLH, int soLuongNH,DateTime datetp_Batdau,DateTime dateTP_ngayKT)
        {
            return DalSach.XemThongKe(soLuongLH, soLuongNH, datetp_Batdau, dateTP_ngayKT);
        }
    }
}
